def confirm(msg)
  puts msg+'[y/n]?'
  f = STDIN.gets
  exit unless /y(es)?/i=~f
end
DEFALUT_MSG = 'Format the sources and add the comments'
SCRIPT='script/hgs/'

require 'yaml'
CONF= YAML.load_file('.auths.yml')

CHOOSE_DEST = CONF['dest'].to_s
CHOOSE_USER = CONF[CHOOSE_DEST+'_user'].to_s
CHOOSE_PASSWD = CONF[CHOOSE_DEST+'_passwd'].to_s
CHOOSE_SERVER= CONF[CHOOSE_DEST+'_server'].to_s
CHOOSE_PRO = CONF[CHOOSE_DEST+'_pro'].to_s
CHOOSE_PATH = CONF[CHOOSE_DEST+'_path'].to_s

PUSH = SCRIPT+'push'
desc 'Commit sources'
task :ci,:msg do |t,args|
  args.with_defaults(:msg => DEFALUT_MSG)
  confirm('Commit with message: '+args.msg) if DEFALUT_MSG==args.msg
  # Push source
  sh PUSH,args.msg,CHOOSE_USER,CHOOSE_PASSWD, CHOOSE_SERVER, CHOOSE_PATH, CHOOSE_PRO
end

PULL = SCRIPT+'pull'
desc 'Pull the project from the source'
task :pull do
  # Push source
  sh PULL,'', CHOOSE_USER, CHOOSE_PASSWD, CHOOSE_SERVER, CHOOSE_PATH, CHOOSE_PRO
end

CLONE = SCRIPT+'clone'
desc 'Clone the local project to the server'
task :clone do
  # Push source
  sh CLONE,'',CHOOSE_USER,CHOOSE_PASSWD, CHOOSE_SERVER, CHOOSE_PATH, CHOOSE_PRO
end

desc 'Tar hg.tar.gz'
task :hgtar do
  sh 'tar', '-cpzf', 'hg.tar.gz', '.hg'
end
